package com.juc.cyclicbarrier.cyclicbarrier8;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class MyService {
   /**
    * 方法reset()的作用是重置屏障
    */
	public CyclicBarrier cyclicBarrier= new CyclicBarrier(3, new Runnable() {
		
		@Override
		public void run() {
		      System.out.println("  彻底结束了  " + System.currentTimeMillis());
			
		}
	});
	
	public void testMethod() {
		
		try {
			System.out.println(Thread.currentThread().getName() + " 准备 ！" + System.currentTimeMillis());
			cyclicBarrier.await();
			System.out.println(Thread.currentThread().getName() + " 结束 ！" + System.currentTimeMillis());

		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (BrokenBarrierException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
}
